package com.suarte.webapp.action;

import com.suarte.core.WorkType;
import java.io.Serializable;
import org.appfuse.service.GenericManager;

/**
 * Created by IntelliJ IDEA.
 * User: Gcastillo
 * Date: Jan 13, 2011
 * Time: 9:57:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class WorkTypeForm extends BasePage implements Serializable{
    private GenericManager<WorkType, Long> workTypeManager;
    private WorkType workType = new WorkType();
    private Long id;

    public void setWorkTypeManager(GenericManager<WorkType, Long> workTypeManager) {
        this.workTypeManager = workTypeManager;
    }

    public WorkType getWorkType() {
        return workType;
    }

    public void setWorkType(WorkType workType) {
        this.workType = workType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        workTypeManager.remove(workType.getId());
        addMessage("workType.deleted");

        return "list";
    }

    public String edit() {
        if (id != null) {
            workType = workTypeManager.get(id);
        } else {
            workType = new WorkType();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (workType.getId() == null);
        workTypeManager.save(workType);

        String key = (isNew) ? "workType.added" : "workType.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
}